#include <iostream>
#include <string>
#include <cstdlib>
#include <boost/bind.hpp>

#include "dispatcher.h"

void global_fun() {
    std::cout << "i'm global fun!" << std::endl;
    sleep(1);
}

// \cond HIDDEN_SYMBOLS
struct functor 
{
    void operator()()
    {
        std::cout << "i'm a functor!" << std::endl;
        sleep(1);
    }
};

struct foo
{
    void print_msg(std::string msg) {
        std::cout << msg << std::endl;
    }
};

// \endcond

/** 
 * Demonstrates different ways of posting jobs to the dispatcher
 *
 */
struct dispatcher_example {
    void run()
    {
        {
            dispatcher disp;
            
            // using boost bind on a global function
            disp.post(boost::bind(&global_fun));

            // using a function object (functor)
            functor func;
            disp.post(func);

            // using on a member function with argument
            foo f;
            disp.post(boost::bind(&foo::print_msg, &f, "i'm a member function!"));

            std::string input;
            std::cout << "hit enter to quit..." << std::endl << std::endl;
            std::getline(std::cin, input);

        } // disp destructor called. will wait if a job is running
    }
};

int main()
{
    dispatcher_example example;
    example.run();

    return 0;
}
